home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / e_mac / momlmenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-22  |  6.2 KB  |  257 lines  |  [TEXT/CWIE]

  1. #include <Files.h>
  2. #include <StdLib.h>
  3. #include <Resources.h>
  4. #include <StandardFile.h>
  5. #include "ui.h"
  6. #if defined( THINK_C ) || defined( __MWERKS__ )
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <strings.h>
  10. #endif
  11.  
  12. void CenterRect(Rect *r)
  13. {
  14.     short d;
  15.     Rect *bounds;
  16.     
  17.     bounds = &qd.screenBits.bounds;
  18.     d = r->right - r->left;
  19.     r->left = bounds->left + (bounds->right - bounds->left - d) / 2;
  20.     r->right = r->left + d;
  21.     d = r->bottom - r->top;
  22.     r->top = bounds->top + (bounds->bottom - bounds->top - d) / 3;
  23.     r->bottom = r->top + d;
  24. }
  25.  
  26. void eDoDialog(int sel)
  27. {
  28.   #pragma unused( sel )
  29.   Handle h = GetResource('ALRT', 1025);
  30.   CenterRect((Rect *) *h);
  31.   Alert(1025, nil);
  32. }
  33.  
  34.  
  35. // 19Jul96 e
  36. // open files from selected error reports sich as...
  37. // File "copyrelease.sml", line 6, characters 0-12:
  38. // File "errortest.sml", line 3-6, characters 4-75:
  39.  
  40. /*
  41. static int make_fss( short id, Str255 pname )
  42. {
  43.   OSErr err;
  44.   Boolean isFolder, wasAliased;
  45.   long cur_dir;
  46.   short cur_vol;
  47.  
  48.   HGetVol( NULL, &cur_vol, &cur_dir );
  49.   err = FSMakeFSSpec( cur_vol, cur_dir, pname, &wind_table[id].fss );
  50.   // to deal with aliases...
  51.   if( err != noErr
  52.       || ResolveAliasFile( &wind_table[id].fss, 1, &isFolder, &wasAliased ) != noErr )
  53.     return -1;
  54.   return 0;
  55. }
  56. */
  57.  
  58.  
  59. static int edit_file( char *name, int line, int chr, int size )
  60. {
  61.   OSErr err;
  62.   Boolean isFolder, wasAliased;
  63.   long cur_dir;
  64.   short cur_vol;
  65.   Str255 pname;
  66.   FSSpec fss;
  67.  
  68.   HGetVol( NULL, &cur_vol, &cur_dir );
  69.   c_to_p( name, pname );
  70.   err = FSMakeFSSpec( cur_vol, cur_dir, pname, &fss );
  71.   // to deal with aliases...
  72.   if( err != noErr
  73.       || ResolveAliasFile( &fss, 1, &isFolder, &wasAliased ) != noErr )
  74.     return -1;
  75.   edit( &fss, line, chr, size );
  76.   return 0;
  77. }
  78.  
  79. void find_error(char *txt)
  80. { // text is mutable!
  81.   int chr = 0;
  82.   int line = 0;
  83.   int size = 0;
  84.   char *fst = strstr( txt, "File \"" );
  85.   if( fst != NULL )
  86.   { char *snd = &fst[6];
  87.     char *thd = strchr( snd, '\"' );
  88.     if( thd != NULL )
  89.     { // snd is the file name
  90.       *thd++ = 0; // terminated
  91.       txt = snd;  // txt is the file name
  92.       // parse position
  93.       fst = strstr( thd, "line " );
  94.       if( fst != NULL ) line = strtol( &fst[5], &thd, 10 );
  95.       fst = strstr( thd, "characters " );
  96.       if( fst != NULL ) chr = strtol( &fst[11], &thd, 10 );
  97.       if( *thd == '-' ) size = atol( &thd[1] );
  98.       if( size > chr ) size -= chr;
  99.     }
  100.   }
  101.   if(edit_file( txt, line, chr, size )) SysBeep( 3 );
  102. }
  103.  
  104. /* 09Jan95 e */
  105. static FileFilterUPP compile_filterUPP = NULL;
  106. static FileFilterUPP source_filterUPP = NULL;
  107. static FileFilterUPP object_filterUPP = NULL;
  108.  
  109. static pascal Boolean compile_filter (ParmBlkPtr pb)
  110. {
  111.   char len = pb->fileParam.ioNamePtr [0];
  112.   if (len >= 4
  113.       && pb->fileParam.ioNamePtr [len    ] == 'l'
  114.       && pb->fileParam.ioNamePtr [len - 1] == 'm'
  115.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  116.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  117.     return 0;
  118.   }else if (len >= 4
  119.       && pb->fileParam.ioNamePtr [len    ] == 'g'
  120.       && pb->fileParam.ioNamePtr [len - 1] == 'i'
  121.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  122.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  123.     return 0;
  124.   }else{
  125.     return 1;
  126.   }
  127. }
  128.  
  129. static pascal Boolean source_filter (ParmBlkPtr pb)
  130. {
  131.   char len = pb->fileParam.ioNamePtr [0];
  132.   if (len >= 4
  133.       && pb->fileParam.ioNamePtr [len    ] == 'l'
  134.       && pb->fileParam.ioNamePtr [len - 1] == 'm'
  135.       && pb->fileParam.ioNamePtr [len - 2] == 's'
  136.       && pb->fileParam.ioNamePtr [len - 3] == '.'){
  137.     return 0;
  138.   }else{
  139.     return 1;
  140.   }
  141. }
  142.  
  143. static pascal Boolean object_filter (ParmBlkPtr pb)
  144. {
  145.   char len = pb->fileParam.ioNamePtr [0];
  146.   if (len >= 3
  147.       && pb->fileParam.ioNamePtr [len    ] == 'o'
  148.       && pb->fileParam.ioNamePtr [len - 1] == 'u'
  149.       && pb->fileParam.ioNamePtr [len - 2] == '.'){
  150.     return 0;
  151.   }else{
  152.     return 1;
  153.   }
  154. }
  155.  
  156. static char postfix [] = ":";
  157. #ifdef THINK_C
  158. static char nocd_template [] = "%s \"%#s\";";
  159. static char cd_template [] = "chDir \"%s\"; %s \"%#s\";";
  160. #else
  161. static char nocd_template [] = "%s \"%s\";";
  162. static char cd_template [] = "chDir \"%s\"; %s \"%s\";";
  163. #endif
  164.  
  165. static void do_file (char *command, long type, FileFilterUPP filter)
  166. {
  167.   SFTypeList type_list;
  168.   StandardFileReply reply;
  169.   short cur_vol;
  170.   long cur_dir;
  171.   char *buf, dir[512];
  172.   
  173.   type_list [0] = type;
  174.   StandardGetFile ( filter, 1, type_list, &reply );
  175.   if (!reply.sfGood) return;
  176. #ifndef THINK_C
  177.   p2cstr (reply.sfFile.name);
  178. #endif
  179.   HGetVol( NULL, &cur_vol, &cur_dir ); // 30Aug95 e
  180.   if ( cur_vol == reply.sfFile.vRefNum && cur_dir == reply.sfFile.parID )
  181.   { buf = malloc (sizeof (nocd_template) - 4
  182.           + strlen (command)
  183. #ifdef THINK_C
  184.           + reply.sfFile.name[0]);
  185. #else
  186.           + strlen ((char *)reply.sfFile.name));
  187. #endif
  188.     if (buf == NULL) return;
  189.     sprintf (buf, nocd_template, command, reply.sfFile.name);
  190.   }else{
  191.     // dir = get_wd_name (reply.sfFile.vRefNum, postfix);
  192.     getfullpath( reply.sfFile.vRefNum,
  193.                  reply.sfFile.parID,
  194.                  "\p", // postfix unnecessary
  195.                  dir, 511, 0 );
  196.     buf = malloc (sizeof (cd_template) - 6
  197.           + strlen (dir)
  198.           + strlen (command)
  199. #ifdef THINK_C
  200.           + reply.sfFile.name[0]);
  201. #else
  202.           + strlen ((char *)reply.sfFile.name));
  203. #endif
  204.     if (buf == NULL) return;
  205.     sprintf (buf, cd_template, dir, command, reply.sfFile.name);
  206.     // if (dir != postfix) free (dir - 1);           /* cf.get_wd_name */
  207.   }
  208.   send_to_caml (buf);
  209.   free (buf);
  210. }
  211.  
  212. static void ensure_ff_upp (void)
  213. { if ( compile_filterUPP == NULL )
  214.   { compile_filterUPP = NewFileFilterProc(compile_filter);
  215.     source_filterUPP  = NewFileFilterProc(source_filter);
  216.     object_filterUPP  = NewFileFilterProc(object_filter);
  217.   }
  218. }
  219.  
  220. void do_include (void)
  221. {
  222.   ensure_ff_upp();
  223.   do_file ("use", 'TEXT', source_filterUPP);
  224. }
  225.  
  226. void do_compile (void)
  227. {
  228.   ensure_ff_upp();
  229.   do_file ("compile", 'TEXT', compile_filterUPP);
  230. }
  231.  
  232. void do_load (void)
  233. {
  234.   ensure_ff_upp();
  235.   do_file ("loadOne", 'BINA', object_filterUPP);
  236. }
  237.  
  238. void do_load_object (void)
  239. {
  240.   ensure_ff_upp();
  241.   do_file ("load", 'BINA', object_filterUPP);
  242. }
  243.  
  244. void do_gc (void)
  245. {
  246. #if 0
  247.   send_to_caml ("gc_full_major();");
  248. #else
  249.   send_to_caml("local prim_val gc : unit -> unit = 1 \"gc_full_major\" in val _ = gc() end;");
  250. #endif
  251. }
  252.  
  253. void do_help (void)
  254. {
  255.   send_to_caml ("help \"\";");
  256. }
  257.